#
# Cookbook Name:: java
# Recipe:: install
# Install JRE
# Copyright 2013, IBM
#
# All rights reserved - Do Not Redistribute
#

cuser = node[:chef][:user]
cgroup = node[:chef][:group]
deployment = node[:deployment]
inst_temp = node[:common][:inst_temp]+"/java7"

startinstr "Install java 7"

include_recipe "gitclientsetup::default"

directory "#{inst_temp}" do
	user cuser
	group cgroup
	action :create
end

directory "#{inst_temp}/#{node[:java7][:version]}" do
	user cuser
	group cgroup
	action :create
end


# Fetch the java7 zip file
bash "fetch java7 package" do
	user cuser
	group cgroup
 	cwd "#{inst_temp}/#{node[:java7][:version]}"
	creates "/tmp/fetch-java.done"
	code <<-EOH
		scp #{node[:common][:scp_repo]}/#{node[:java7][:installer_path]} . && touch "/tmp/fetch-java.done"
	EOH
end


bash "install java7 package" do
	cwd "#{inst_temp}/#{node[:java7][:version]}"
	creates "/opt/ibm/#{node[:java7][:version]}"
	code <<-EOH
		mkdir -p #{node['java7']['installDir']}
		cd #{node['java7']['installParentDir']}
		tar -zxvf #{inst_temp}/#{node[:java7][:version]}/$(basename #{node[:java7][:installer_path]})
	EOH
end

stopinstr "Install java7"
